import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
// import { dictItemCheck } from './api';
// import { rules } from '/@/utils/helper/validator';
import { h } from 'vue';

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'title',
    width: 240,
  },
  {
    title: '链接',
    dataIndex: 'link',
    width: 240,
  },
  {
    title: '点击前图标',
    dataIndex: 'beginImg',
    width: 120,
    customRender: ({ text }) => {
      return h('img', {
        src: `${import.meta.env.VITE_GLOB_ONLINE_VIEW_URL}${text}`,
        style: {
          width: '32px',
          height: '32px',
          objectFit: 'cover',
        },
      });
    },
  },
  {
    title: '点击后图标',
    dataIndex: 'beforeImg',
    width: 120,
    customRender: ({ text }) => {
      return h('img', {
        src: `${import.meta.env.VITE_GLOB_ONLINE_VIEW_URL}${text}`,
        style: {
          width: '32px',
          height: '32px',
          objectFit: 'cover',
        },
      });
    },
  },
];

export const recycleBincolumns: BasicColumn[] = [
  {
    title: '字典名称',
    dataIndex: 'title',
    width: 120,
  },
  {
    title: '字典编码',
    dataIndex: 'icon',
    width: 120,
  },
  {
    title: '描述',
    dataIndex: 'path',
    width: 120,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '菜单名称',
    field: 'title',
    component: 'JInput',
    colProps: { span: 6 },
  },
  // {
  //   label: '字典编码',
  //   field: 'dictCode',
  //   component: 'JInput',
  //   colProps: { span: 6 },
  // },
];

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '名称',
    field: 'title',
    required: true,
    component: 'Input',
  },
  {
    label: '链接',
    field: 'link',
    component: 'Input',
    required: true,
    // dynamicDisabled: ({ values }) => {
    //   return !!values.id;
    // },
    // dynamicRules: ({ model, schema }) => rules.duplicateCheckRule('sys_dict', 'dict_code', model, schema, true),
  },
  {
    label: '点击前图标',
    field: 'beginImg',
    component: 'JImageUpload',
    required: true,
    componentProps: {
      fileMax: 1,
    },
  },
  {
    label: '点击后图标',
    field: 'beforeImg',
    component: 'JImageUpload',
    required: true,
    componentProps: {
      fileMax: 1,
    },
  },
  // {
  //   label: '描述',
  //   field: 'description',
  //   component: 'Input',
  // },
];

export const dictItemColumns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'itemText',
    width: 80,
  },
  {
    title: '数据值',
    dataIndex: 'itemValue',
    width: 80,
  },
  {
    title: '字典颜色',
    dataIndex: 'itemColor',
    width: 80,
    align: 'center',
    customRender: ({ text }) => {
      return h('div', {
        style: { background: text, width: '18px', height: '18px', 'border-radius': '50%', margin: '0 auto' },
      });
    },
  },
];

export const dictItemSearchFormSchema: FormSchema[] = [
  {
    label: '名称',
    field: 'itemText',
    component: 'Input',
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'dict_item_status',
      stringToNumber: true,
    },
  },
];

export const itemFormSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '名称',
    field: 'itemText',
    required: true,
    component: 'Input',
  },

  {
    label: '颜色值',
    field: 'itemColor',
    component: 'Input',
    slot: 'itemColor',
  },
  {
    label: '描述',
    field: 'description',
    component: 'Input',
  },
  {
    field: 'sortOrder',
    label: '排序',
    component: 'InputNumber',
    defaultValue: 1,
  },
  {
    field: 'status',
    label: '是否启用',
    defaultValue: 1,
    component: 'JDictSelectTag',
    componentProps: {
      type: 'radioButton',
      dictCode: 'dict_item_status',
      stringToNumber: true,
    },
  },
];
